﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace SocialNetworks.Config
{
	public class FbGraphConfig : Social.Facebook.IFacebookGraphConfig
	{
		public FbGraphConfig(params Social.Facebook.FacebookExtededPermissions[] perms)
		{
			permissions = perms;
			//
			// TODO: Add constructor logic here
			//
		}

		public FbGraphConfig(string accessToken)
		{
			this.AccessToken = accessToken;
		}

		#region IFacebookGraphConfig Members

		public string AccessToken { get; set; }
		public void SaveAccessToken()
		{
			int accountID;
			int.TryParse(HttpContext.Current.Request["ID"], out accountID);
			Logic.BusinessLogic.AccountService.UpdateFbToken(accountID, AccessToken);
		}

		public string AppKey
		{
			get { return ConfigurationManager.AppSettings["fbApiKey"]; }
		}

		public string AuthenticationCode
		{
			get { return HttpContext.Current.Request.QueryString["code"]; }
		}

		public string RedirectUrl
		{
			get { return HttpUtility.UrlEncode(AppParams.URLs.FbRedirectUrl(HttpContext.Current.Request["ID"])); }
		}

		public string SecreteKey
		{
			get { return ConfigurationManager.AppSettings["fbSecretKey"]; }
		}

		public Social.Facebook.FacebookExtededPermissions[] permissions { get; set; }

		#endregion
	}
}